package com.teemor.blog.aop;

import com.alibaba.fastjson.JSONObject;
import com.teemor.common.bean.utils.enums.ResultCode;
import com.teemor.common.bean.utils.tmpl.BaseController;
import com.teemor.common.bean.utils.tmpl.ResponseBen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/11/24 13:55
 */
@RestControllerAdvice
@Slf4j
@Component
public class ExceptionAdvice extends BaseController implements Serializable  {
    private static final long serialVersionUID = 52373014161400701L;

    @ExceptionHandler({ BindException.class })
    public ResponseBen<?> validBindException(BindException e) {
        e.printStackTrace();
        ResponseBen responseBen =new ResponseBen(ResultCode.EXCEPTION.value(), "参数校验失败",null);
        return responseBen;
    }

    @ExceptionHandler({ Exception.class })
    public ResponseBen<?> exception(HttpServletRequest request, Exception e) {
        log.error("内部运行异常:" + request.getServletPath() + request.getContextPath(), e);
        ResponseBen responseBen =new ResponseBen(ResultCode.EXCEPTION.value(), ResultCode.EXCEPTION.msg(),null);
        return responseBen;
    }


}
